﻿using System;
using System.Data;

/// <summary>
/// Summary description for DirectServiceOwner
/// </summary>
public class DirectServiceOwner
{
    private ConnectionBase sgbdr;
    public DirectServiceOwner()
    {
      sgbdr= new ConnectionBase();
    }
    public DataTable GetOwnerForEdit(string codeNumber) // this function for take value to edit
    {

        if (!string.IsNullOrEmpty(codeNumber))
        {
            string sql = "SELECT distinct OWN.CODENUMBER, OWN.BUILDINGID, OWN.LOCATIONID, BUILDING.BUILDING, LOCATION.LOCATION, EMPLOYEE.EMPLOYEENAME, "
                         + "OWN.EMPLOYEEID, EMPLOYEE.EMPLOYEENAME AS Expr1, OWN.unuse, "
                         + "DEPARTMENT.departmentName, TYPEEQUIPMENT.TYPEEQUIPMENT, MODEL.MODEL, SYSTEM.SYSTEM "
                         + "FROM OWN INNER JOIN "
                         + "EQUIPEMENT ON OWN.CODENUMBER = EQUIPEMENT.CODENUMBER INNER JOIN "
                         + "BUILDING ON BUILDING.BUILDINGID = OWN.BUILDINGID INNER JOIN "
                         + "LOCATION ON LOCATION.LOCATIONID = OWN.LOCATIONID INNER JOIN "
                         + "EMPLOYEE ON EMPLOYEE.EMPLOYEEID = OWN.EMPLOYEEID INNER JOIN "
                         + "DEPARTMENT ON DEPARTMENT.departmentID = EMPLOYEE.departmentID INNER JOIN "
                         + "MODEL ON MODEL.MODELID = EQUIPEMENT.MODELID INNER JOIN "
                         + "[IN] ON [IN].modelID = MODEL.MODELID INNER JOIN "
                         + "TYPEEQUIPMENT ON TYPEEQUIPMENT.TYPEEQUIPEMENTID = [IN].typeEquipementID INNER JOIN "
                         + "HAVE ON HAVE.typeEquipementID = TYPEEQUIPMENT.TYPEEQUIPEMENTID INNER JOIN "
                         + "SYSTEM ON SYSTEM.SYSTEMID = HAVE.systemID INNER JOIN "
                         + "EQUIPMENTPURCHASEINFORMATION ON HAVE.haveID = EQUIPMENTPURCHASEINFORMATION.haveID AND "
                         +
                         "EQUIPEMENT.PURCHASEID = EQUIPMENTPURCHASEINFORMATION.PURCHASEID AND EMPLOYEE.EMPLOYEENAME<>'stock' and own.unuse=0  where OWN.CODENUMBER=" + codeNumber ;
            return sgbdr.consultSQL(sql).Tables[0];
        }
        return null;
       
    }
    public DataTable GetCodeNumberByEmployeeId(int employeeId)
    {
        if(employeeId >0)
        {
            string sql = "select codenumber from own where employeeId=" + employeeId;
            return sgbdr.consultSQL(sql).Tables[0];                    
        }
        return null;
       
    }
    public DataTable GetLoaction()
    {
        string sql = "select * from Location";
        return sgbdr.consultSQL(sql).Tables[0];
    }
    public DataTable GetEmployee()
    {

        string sql = "select * from Employee";
        return sgbdr.consultSQL(sql).Tables[0];

    }
    public void UpdateOwner(int employeeId, int buildingId, int locationId, string  dateEnterStr, string codeNumber)
    {
        DateTime dateEnter = new DateTime();
        dateEnter = DateTime.Parse(dateEnterStr); 
        string sql = "update OWN set BUILDINGID=" + buildingId + "," + "LOCATIONID=" + locationId + ","
                     + "EMPLOYEEID=" + employeeId + ",DATEENTER=  '"+ dateEnter +"' where CodeNumber=" + codeNumber;
        sgbdr.executeSQL(sql);

    }

}
